<div class="container">

</div>

<style>
  .container {
    width: 300px;
    padding: 10px;
    height: 300px;
    border: 1px solid red;
    /* contain: layout;*/
    /* contain: size; */
    contain: paint;
    position: relative;
  }

  p {
    position: absolute;
    right: -22px;
    border: 1px solid #333;
    margin: 5px;
    font-size: 14px;
  }
</style>

<script>
  let container = document.querySelector('.container')
  container.addEventListener('click', () => {
    const child = document.createElement('p')
    child.innerHTML = "AAA"
    container.appendChild(child)
  })
</script>